package org.tpdata.api.specialdiseasedata.tianta;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.esotericsoftware.yamlbeans.YamlException;
import common.Data;
import common.RunCaseJson;
import common.SetUpTearDown1;
import exceptions.TestNGRetry;
import io.qameta.allure.Allure;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.FileNotFoundException;

import static common.Login.login;
import static common.TestStep.requestAndRespondBody;

@Feature("获取个人全景病历")
public class getpatientInfo  extends SetUpTearDown1 {

    Logger log = Logger.getLogger(getpatientInfo.class);
    //    public static final String system = "env.properties";
    Data data = login();

    business.specialdiseasedata.CreateTemplate ct = new business.specialdiseasedata.CreateTemplate();
    String id;

    {
        try {
            id = ct.getpatientid();
        } catch (ConfigurationException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (YamlException e) {
            e.printStackTrace();
        }
    }

    
   
/*     住院
     *inpatientNo  =ZY050000618692_1
     * @Description:
     * @param
     * @return java.lang.String
     * @author gujinle
     * @date 2021-09-01 16:12
     */
    public String getinpatientNo() {
        JSONObject json = new JSONObject();
//        Map<String,String > json=new HashMap<String, String>();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("id", id);
        json.put("page", 1);
        json.put("size",10);
        json.put("startDate", "");//2016-09-18
        json.put("endDate", ""); //2018-02-02

        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/hospitalization/perioperativeRecordMaster.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
//        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/hospitalization/perioperativeRecordMaster.json";
//        requestAndRespondBody(url, json, jsonStr);
        JSONObject obj = JSONObject.parseObject(jsonStr);
        String inpatientNo = obj.getJSONObject("responseData").getJSONArray("content").getJSONObject(0).getString("inpatientNo");
        return inpatientNo;
    }

/*
    * 诊断
    * @Description: 
     * @param 	
    * @return java.lang.String
    * @author gujinle
    * @date 2021-09-13 15:14
    */
    public String getdataId() {
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("id", id);
        json.put("startDate", "");//2016-09-18
        json.put("endDate", "");//2018-02-02
        json.put("size", 10);
        json.put("page", 1);
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/data/getDiagnosisAssistMaster.json");
        String jsonStr = response.asString();
        JSONObject obj = JSONObject.parseObject(jsonStr);
        JSONObject jb = obj.getJSONObject("responseData").getJSONArray("content").getJSONObject(0);
        String dataId = jb.getString("dataId");
        return dataId;
    }
    @Story("获取患者全景数据")
    @Test(retryAnalyzer = TestNGRetry.class, description = "获取患者个人基本信息")
    public void runCase() {
        JSONObject json = new JSONObject();
//        Map<String,String > json=new HashMap<String, String>();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("create_id", data.getUserId());
        json.put("authName", data.getUserName());
//        json.put("size", -1);
        json.put("patiId", id);

        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-primary-index/identifier/getInfo.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断msg字段是否：成功");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-primary-index/identifier/getInfo.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String msg = obj.getString("msg");
        Assert.assertEquals(msg, "成功");
    }

    @Test(retryAnalyzer = TestNGRetry.class, description = "首页-预警汇总-查询最后一次检验指标预警数据")
    public void runCase2() {

        JSONObject json = new JSONObject();
//        Map<String,String > json=new HashMap<String, String>();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("create_id", data.getUserId());
        json.put("authName", data.getUserName());
//        json.put("page", 1);
//        json.put("size", -1);
        json.put("patiId", id);

        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/panorama/data/warnIndicatorList.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);

        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/panorama/data/warnIndicatorList.json";
        requestAndRespondBody(url, json, jsonStr); //写进Allure报告
        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");

    }

    @Test(retryAnalyzer = TestNGRetry.class, description = "首页-查看患者基本信息")
    public void runCase3() {

        JSONObject json = new JSONObject();
//        Map<String,String > json=new HashMap<String, String>();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("create_id", data.getUserId());
//        json.put("page", 1);
//        json.put("size", -1);
        json.put("patiId", id);
        json.put("hospitalCode", "");
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/panorama/data/getPatientInfo.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);

        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/panorama/data/getPatientInfo.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }

    @Test(retryAnalyzer = TestNGRetry.class, description = "预警汇总-查询检验预警指标趋势分析数据")
    public void runCase4() {
        JSONObject json = new JSONObject();
//        Map<String,String > json=new HashMap<String, String>();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("testItem", "嗜酸性粒细胞数");
        json.put("startDate", "2016-09-18");   //需要有数据
        json.put("endDate", "2018-02-02");   //需要有数据
        json.put("patiId", id);
        json.put("itemCode", "");
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/panorama/data/eosinophilCountList.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);

        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");

        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/panorama/data/eosinophilCountList.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);

        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }

    @Test(retryAnalyzer = TestNGRetry.class, description = "首页-患者时间轴-查询时间轴数据【住院诊断，门诊诊断，吸烟，临床主要诊断，胸部影像学】数据")
    public void runCase5() {

        JSONObject json = new JSONObject();
//        Map<String,String > json=new HashMap<String, String>();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("startDate", "2016-09-18");
        json.put("endDate", "2018-02-02");
        json.put("patiId", id);
//        json.put("hospitalCode", "");
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/panorama/data/getTimeAxisList.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/panorama/data/getTimeAxisList.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }

    @Test(retryAnalyzer = TestNGRetry.class, description = "首页-门诊住院统计-查询住院费用和天数据")
    public void runCase6() {

        JSONObject json = new JSONObject();
//        Map<String,String > json=new HashMap<String, String>();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("startDate", "2016-09-18");
        json.put("endDate", "2018-02-02");
        json.put("patiId", id);
//        json.put("hospitalCode", "");
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/panorama/data/getTotalCosts.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/panorama/data/getTotalCosts.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }

    @Test(retryAnalyzer = TestNGRetry.class, description = "首页-门诊住院统计-查询门诊，住院合并系统疾病")
    public void runCase7() {

        JSONObject json = new JSONObject();
//        Map<String,String > json=new HashMap<String, String>();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("startDate", "2016-09-18");
        json.put("endDate", "2018-02-02");
        json.put("patiId", id);
//        json.put("hospitalCode", "");
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/panorama/data/getMainDiagTypeRatio.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/panorama/data/getMainDiagTypeRatio.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }


    @Test(retryAnalyzer = TestNGRetry.class, description = "首页-门诊住院统计-查询门诊和住院主要诊断类型的比率数据")
    public void runCase8() {

        JSONObject json = new JSONObject();
//        Map<String,String > json=new HashMap<String, String>();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("startDate", "2016-09-18");
        json.put("endDate", "2018-02-02");
        json.put("patiId", id);
//        json.put("hospitalCode", "");
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/panorama/data/getMainDiagRatio.json");
        String jsonStr = response.asString();
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        log.info("响应报文：" + jsonStr);
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/panorama/data/getMainDiagRatio.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }

    @Test(retryAnalyzer = TestNGRetry.class, description = "查询访视，门诊，住院的次数")
    public void runCase9() {
        JSONObject json = new JSONObject();
//        Map<String,String > json=new HashMap<String, String>();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());

        json.put("patiId", id);
        json.put("hospitalCode", "");
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/panorama/data/getStatisticsCount.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/panorama/data/getStatisticsCount.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }




    /*    * 门诊
     * @Description:
     * @param
     * @return java.lang.String
     * @author gujinle
     * @date 2021-09-14 11:19*/

    public String getAssistMaster() {
        JSONObject json = new JSONObject();
//        Map<String,String > json=new HashMap<String, String>();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("id", id);
        json.put("org_ids",true);
        json.put("reportName", "clinicDiagnosis");
        json.put("startDate",""); //"2016-09-18"
        json.put("endDate", "");//"2018-02-02"
        json.put("page", 1);
        json.put("size", 10);
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/data/getClinicDiagnosisAssistMaster.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/data/getClinicDiagnosisAssistMaster.json";
        requestAndRespondBody(url, json, jsonStr);
        return jsonStr;
    }

    /*
        门诊信息-获取列表中第一个门诊的门诊的outPatientNo，hospitalCode
    */
    String jsonStr = getAssistMaster();
    JSONObject obj = JSONObject.parseObject(jsonStr);
    JSONArray js = obj.getJSONObject("responseData").getJSONArray("content");
    String outPatientNo = js.getJSONObject(0).getString("outpPatientNo");     //outpPatientNo : "22716829_1"
    String hospitalCode = js.getJSONObject(0).getString("hospitalCode"); //hospitalCode : "YS0001"



    @Test(retryAnalyzer = TestNGRetry.class, description = "门诊信息-获取全部门诊列表信息")
    public void runCase10() {
        String jsonStr = getAssistMaster();

        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");

    }


/*
*
* @Description: 门诊信息
 * @param null
* @return
* @author gujinle
* @date 2021-09-13 14:38
*/

    @Test(retryAnalyzer = TestNGRetry.class, description = "门诊信息-获取列表中第一个门诊的门诊详情-诊断")
    public void runCase11() {
        JSONObject json = new JSONObject();
//        Map<String,String > json=new HashMap<String, String>();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("reportName", "clinicDiagnosis");
        json.put("patientNo", "");
        json.put("outPatientNo", outPatientNo);
        json.put("hospitalCode", hospitalCode);
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/data/getClinicDiagnosisAssistDetail.json");
        String str = response.asString();
        log.info("响应报文：" + str);
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/data/getClinicDiagnosisAssistDetail.json";
        requestAndRespondBody(url, json, str);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");

        JSONObject jb = JSONObject.parseObject(str);
        String responseResult = jb.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }

    @Test(retryAnalyzer = TestNGRetry.class, description = "门诊信息-获取列表中第一个门诊的门诊详情-医嘱")
    public void runCase12() {
        JSONObject json = new JSONObject();
//        Map<String,String > json=new HashMap<String, String>();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("reportName", "clinicOrdersDetail");
//        json.put("patientNo", "");
        json.put("outPatientNo", outPatientNo);
        json.put("hospitalCode", hospitalCode);
        json.put("page", 1);
        json.put("size", 10);
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/data/getClinicOrdersDetailAssistDetail.json");
        String str = response.asString();
        log.info("响应报文：" + str);
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/data/getClinicOrdersDetailAssistDetail.json";
        requestAndRespondBody(url, json, str);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");

        JSONObject jb = JSONObject.parseObject(str);
        String responseResult = jb.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }


    /* 住院*/


    @Test(retryAnalyzer = TestNGRetry.class, description = "全景数据-住院-病案首页-病历列表")
    public void runCase13() {

        JSONObject json = new JSONObject();
//        Map<String,String > json=new HashMap<String, String>();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("id", id);
        json.put("page", 1);
        json.put("size", 10);
//        json.put("startDate", "2016-09-18");
//        json.put("endDate", "2018-02-02");

        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/hospitalization/perioperativeRecordMaster.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/hospitalization/perioperativeRecordMaster.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }

    String inpatientNo = getinpatientNo();

    @Test(retryAnalyzer = TestNGRetry.class, description = "全景数据-住院-病案首页-住院病案首页详情")
    public void runCase14() {

        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("reportName", "inpMrFrontSheet");
        json.put("inpatientNo", inpatientNo);
        json.put("hospitalCode", hospitalCode);
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/panorama/data/getInpMrFrontSheetById.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/panorama/data/getInpMrFrontSheetById.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");

    }

    @Test(retryAnalyzer = TestNGRetry.class, description = "全景数据-住院-入院记录-入院详情")
    public void runCase15() {

        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("reportName", "admissionMr");
        json.put("inpatientNo", inpatientNo);
        json.put("hospitalCode", hospitalCode);
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/panorama/data/getAdmissionMrAssistDetail.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/panorama/data/getAdmissionMrAssistDetail.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }

    @Test(retryAnalyzer = TestNGRetry.class, description = "全景数据-住院-出院记录-出院详情")
    public void runCase16() {

        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("reportName", "dischgedMr");
        json.put("inpatientNo", inpatientNo);
        json.put("hospitalCode", hospitalCode);
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/panorama/data/getDischgedMrAssistDetail.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/panorama/data/getDischgedMrAssistDetail.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }


    @Test(retryAnalyzer = TestNGRetry.class, description = "全景数据-住院-病程记录-首次病程记录右侧数据")
    public void runCase17() {

        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("inpatientNo", inpatientNo);
        json.put("hospitalCode", hospitalCode);
        json.put("type", "1");   //1:首次病程记录;2:日常病程记录;3:上级医师查房记录;4:抢救记录;5:转入记录;6:转出记录;
        // 7:操作记录;8:会诊记录;9:输血记录;10:阶段小结；11:疑难病例套路记录;12:死亡病例套路记录;13:死亡记录;

        json.put("size", 10);
        json.put("page", 1);
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/progressRec/getProgressRecDetail.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/progressRec/getProgressRecDetail.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }

    /*诊断*/


    String dataId = getdataId();

    @Test(retryAnalyzer = TestNGRetry.class, description = "全景数据-诊断-全部诊断")
    public void runCase18() {
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("id", id);
        json.put("startDate", "");//2016-09-18
        json.put("endDate", "");//        json.put("endDate", "");
        json.put("size", 10);
        json.put("page", 1);
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/data/getDiagnosisAssistMaster.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/data/getDiagnosisAssistMaster.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }


    @Test(retryAnalyzer = TestNGRetry.class, description = "全景数据-诊断-全部诊断-右侧诊断详情")
    public void runCase19() {
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("dataId", dataId);
        json.put("hospitalCode", hospitalCode);
        json.put("type", 2);
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/data/getDiagnosisAssistDetail.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/data/getDiagnosisAssistDetail.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }


    /*  肺功能检查*/

    @Test(retryAnalyzer = TestNGRetry.class, description = "全景数据-肺功能检查-肺功能检查列表")
    public void runCase20() {
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("reportName", "examReportMaster");
        json.put("startDate", "");//2016-09-18
        json.put("endDate", ""); //2018-02-02
        json.put("id", id);
        json.put("size",10);
        json.put("page", 1);
        json.put("sort", "desc");
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/panorama/data/getExamReportMasterAssistMaster.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/panorama/data/getExamReportMasterAssistMaster.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }


    @Test(retryAnalyzer = TestNGRetry.class, description = "全景数据-肺功能检查-趋势分析-指标类型")
    public void runCase21() {
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("type", 2);
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/data/getReportTempList.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/data/getReportTempList.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }

    @Test(retryAnalyzer = TestNGRetry.class, description = "全景数据-肺功能检查-趋势分析-指标筛选值")
    public void runCase22() {
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("id", "8");  //从api-es/data/getReportTempList.json接口获取的指标类型ID；8-预计值，9-最佳或药前，10-最佳（药前）/预计，11-舒张后最大值 等等
        json.put("name", "");
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/data/getReportTempDetailList.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/data/getReportTempDetailList.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }


    /*治疗用药*/
    @Test(retryAnalyzer = TestNGRetry.class, description = "全景数据-治疗用药-全部医嘱用药-左侧列表")
    public void runCase23() {
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("id", id);
//        json.put("startDate", "2016-09-18");
//        json.put("endDate", "2018-02-02");
        json.put("page", 1);
        json.put("size", 10);
        json.put("sort", "desc");
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/panorama/data/getDrugAssistMaster.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/panorama/data/getDrugAssistMaster.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }

    @Test(retryAnalyzer = TestNGRetry.class, description = "全景数据-治疗用药-全部医嘱用药-右侧用药详情")
    public void runCase24() {
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("reportName", "visitOrder");
//        json.put("startDate", "2016-09-18");
//        json.put("endDate", "2018-02-02");
        json.put("page", 1);
        json.put("size", 10);
        json.put("inpatientNo", outPatientNo);
        json.put("type", "门诊");
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/panorama/data/getDrugAssistDetail.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/panorama/data/getDrugAssistDetail.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }

    /*检验*/
    @Test(retryAnalyzer = TestNGRetry.class, description = "全景数据-检验-全部检验记录-左侧检验列表")
    public void runCase25() {
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("reportName", "visitLab");
        json.put("id", id);
        json.put("startDate", "");   //2016-09-18
        json.put("endDate", "");    //2018-02-02
        json.put("page", 1);
        json.put("size", 10);
        json.put("sort", "desc");
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/panorama/data/getVisitLabAssistMaster.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/panorama/data/getVisitLabAssistMaster.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }

    @Test(retryAnalyzer = TestNGRetry.class, description = "全景数据-检验-全部检验记录-右侧检验信息详情")
    public void runCase26() {
        /*运行 api-es/panorama/data/getDrugAssistMaster.json接口*/
        JSONObject json1 = new JSONObject();
        json1.put("access_token", data.getAccessToken());
        json1.put("authToken", data.getAccessToken());
        json1.put("uniqu_no", data.getUniquNo());
        json1.put("operatorId", data.getUserId());
        json1.put("authUserId", data.getUserId());
        json1.put("authName", data.getUserName());
        json1.put("reportName", "visitLab");
        json1.put("id", id);
        json1.put("startDate", "");   //2016-09-18
        json1.put("endDate", "");    //2018-02-02
        json1.put("page", 1);
        json1.put("size", 10);
        json1.put("sort", "desc");
        log.info("请求报文：" + json1.toString());
        Response response1 = RunCaseJson.runCase(json1, "get", "api-es/panorama/data/getVisitLabAssistMaster.json");
        String str = response1.asString();
        log.info("响应报文：" + str);
        JSONObject jb = JSONObject.parseObject(str);
        JSONObject jb1 = jb.getJSONObject("responseData").getJSONArray("content").getJSONObject(0).getJSONArray("mapList").getJSONObject(0);
        String labSerialNum = jb1.getString("labSerialNum");
        String packageItem = jb1.getString("packageItem");

        /*调用 api-es/data/getVisitLabPageAssistDetail.json接口*/
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("reportName", "visitLab");
        json.put("labSerialNum", labSerialNum);
        json.put("packageItem", packageItem);
        json.put("page", 1);
        json.put("size", 10);
        json.put("hospitalCode", hospitalCode);
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/data/getVisitLabPageAssistDetail.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/data/getVisitLabPageAssistDetail.json";
        requestAndRespondBody(url, json, jsonStr);

        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }


    /*检查*/
    @Test(retryAnalyzer = TestNGRetry.class, description = "全景数据-检查-全部检查记录-右侧检查详情")
    public void runCase27() {
      /*调用左侧列表*/
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("reportName", "visitCheck");
        json.put("id", id);
        json.put("startDate", "");//2016-09-18
        json.put("endDate", "");//2018-02-02
        json.put("page", 1);
        json.put("size", 10);
        json.put("sort", "desc");
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/panorama/data/getVisitCheckAssistMaster.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/panorama/data/getVisitCheckAssistMaster.json";
        requestAndRespondBody(url, json, jsonStr);
        JSONObject obj = JSONObject.parseObject(jsonStr);
        JSONObject jb = obj.getJSONObject("responseData").getJSONArray("content").getJSONObject(0).getJSONArray("mapList").getJSONObject(0);
        String checkserialnum = jb.getString("checkserialnum");

/*调用右侧详情*/

        JSONObject json1 = new JSONObject();
        json1.put("access_token", data.getAccessToken());
        json1.put("authToken", data.getAccessToken());
        json1.put("uniqu_no", data.getUniquNo());
        json1.put("operatorId", data.getUserId());
        json1.put("authUserId", data.getUserId());
        json1.put("authName", data.getUserName());
        json1.put("reportName", "visitCheck");
        json1.put("checkserialnum", checkserialnum);
        json1.put("hospitalCode", hospitalCode);

        log.info("请求报文：" + json1.toString());
        Response response1 = RunCaseJson.runCase(json1, "get", "api-es/data/getVisitCheckAssistDetail.json");
        String str = response1.asString();
        log.info("响应报文：" + str);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url1 = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/data/getVisitCheckAssistDetail.json";
        requestAndRespondBody(url1, json1, str);
        JSONObject obj1 = JSONObject.parseObject(str);
        String responseResult = obj1.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");

    }

    /*治疗时间轴*/
    @Test(retryAnalyzer = TestNGRetry.class, description = "全景数据-治疗时间轴-全部住院记录-左侧列表")
    public void runCase28() {
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("id", id);
//        json.put("startDate", "2016-09-18");
//        json.put("endDate", "2018-02-02");
        json.put("page", 1);
        json.put("size", 10);
        json.put("sort", "desc");
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/panorama/data/getTreatmentTimeAxisMaster.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/panorama/data/getTreatmentTimeAxisMaster.json";
        requestAndRespondBody(url, json, jsonStr);
        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }

    @Test(retryAnalyzer = TestNGRetry.class, description = "全景数据-治疗时间轴-全部住院记录-右侧时间轴")
    public void runCase29() {
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("inpatientNo", inpatientNo);

        json.put("hospitalCode", hospitalCode);
        log.info("请求报文：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", "api-es/similar/data/getTimeAxis.json");
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        Allure.addAttachment("判断依据", "判断responseResult字段是否为success");
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + "api-es/similar/data/getTimeAxis.json";
        requestAndRespondBody(url, json, jsonStr);
        JSONObject obj = JSONObject.parseObject(jsonStr);
        String responseResult = obj.getString("responseResult");
        Assert.assertEquals(responseResult, "SUCCESS");
    }

  /*   test*/
}

